﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using HaSdkWrapper;

namespace HaSdkDemo
{
    public partial class FormIPList : Form
    {
        private discover_ipscan_cb_t callback;

        public FormIPList()
        {
            InitializeComponent();
        }

        private void FormIPList_Load(object sender, EventArgs e)
        {
            int suc = -1;

            suc = HaDiscover.discover_client_init();
            if (suc != 0)
            {
                throw new Exception("初始化失败");
            }



            callback = discover_ipscan_cb_t;

            HaDiscover.discover_reg_ipscan_cb(callback, 0);

            suc = -1;
            suc = HaDiscover.discover_ipscan();
            if (suc != 0)
            {
                throw new Exception("error: " + suc);
            }
        }

        public void discover_ipscan_cb_t(ref ipscan_t ipscan, int usr_param)
        {
            Action<ipscan_t> ac = x => listView1.Items.Add(x.ip + " " + x.mac + " " + x.manufacturer);
            this.BeginInvoke(ac, ipscan);
        }

        private void FormIPList_FormClosing(object sender, FormClosingEventArgs e)
        {
            HaDiscover.discover_client_deinit();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            listView1.Items.Clear();
            HaDiscover.discover_ipscan();
        }
    }
}
